#include <QApplication>
#include <main.h>
//================ setting LoginList.ini =========================
QSettings settings("://home/LoginList.ini", QSettings::IniFormat);
//==================opacity======================================
float opacity = 0.9;
// 将数据写入 INI 文件
//void write_ini_file(const std::vector<std::string>& usernames,
//                    const std::vector<std::string>& passwords,
//                    const std::vector<std::string>& account_properties,
//                    const std::string& filename) {
//    std::ofstream file(filename);
//    if (!file) {
//        std::cerr << "Failed to open file " << filename << std::endl;
//        return;
//    }
//    for (int i = 0; i < usernames.size(); ++i) {
//        file << "[" << usernames[i] << "]" << std::endl;
//        file << "password = " << passwords[i] << std::endl;
//        std::vector<std::string> props = account_properties.at(usernames[i]);

//        file << std::endl;
//    }
//    file.close();
//}

//// 从 INI 文件中读取数据
//void read_ini_file(std::vector<std::string>& usernames,
//                   std::vector<std::string>& passwords,
//                   std::vector<std::string>& account_properties,
//                   const std::string& filename) {
//    std::ifstream file(filename);
//    if (!file) {
//        std::cerr << "Failed to open file " << filename << std::endl;
//        return;
//    }
//    std::string line;
//    std::string section_name;
//    std::map<std::string, std::string> props;
//    while (std::getline(file, line)) {
//        std::istringstream iss(line);
//        char c = iss.get();
//        if (c == '[') {
//            section_name = line.substr(1, line.size() - 2);
//        } else if (c != ';' && line.size() > 0) {
//            std::string key, value;
//            std::getline(iss, key, '=');
//            std::getline(iss, value);
//            if (key == "password") {
//                usernames.push_back(section_name);
//                passwords.push_back(value.substr(1)); // 去掉首个空格
//                account_properties[section_name] = props;
//                props.clear();
//            } else {
//                props[key.substr(1)] = value.substr(1); // 去掉首个空格
//            }
//        }
//    }
//    account_properties[section_name] = props;
//    file.close();
//}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
//    QString inifile = "LoginList.ini";

//    QTextCodec::setCodecForTr(QTextCodec::codecForName( "GB2312" ));
//    QString parameter="-1";
//    LoginPage w(parameter);
    LoginPage w;
    // 设置窗口为无边框并对窗口进行磨砂处理
    w.setAttribute(Qt::WA_TranslucentBackground);
    w.setWindowFlags(Qt::FramelessWindowHint);

    // 设置窗口透明度
    w.setWindowOpacity(opacity);

    // 设置窗口样式表
    w.setStyleSheet("background-color: rgba(0,0,0, 128); border-radius: 10px; color:rgb(255,255,255);");

//    std::string filename = "://homeLoginList.ini";
////    write_ini_file(usernames, passwords, account_properties, filename);
//    std::vector<std::string> usernames2;
//    std::vector<std::string> passwords2;
//    std::vector<std::string>  account_properties2;
//    read_ini_file(usernames2, passwords2, account_properties2, filename);

    QStringList username={};
    QStringList password={};
    w.show();
    QLabel *label = new QLabel(&w);
   label->setGeometry(50, 50, 300, 200);

   QPixmap pixmap("://home/image/bg.jpg");
   label->setPixmap(pixmap);
   label->setScaledContents(true);

   QGraphicsBlurEffect *effect = new QGraphicsBlurEffect;
   effect->setBlurRadius(5);
   label->setGraphicsEffect(effect);

//    unmanedsupermarketsys umsmsys;
//    sysclient sysClient;
//    qint32 state = -1;
//    quint32 state ;
//    if(w.exec() == QDialog::Accepted){
//        umsmsys.show();
//        return a.exec();
//    }else if(w.exec() == QDialog::Rejected){
//        sysClient.show();
//        return a.exec();
//    }else {
//        return 0;
//    }
//    if(state == 0){//页面间跳转
//        umsmsys.show();
//        return a.exec();

//    }else if(state == 1){
//        sysClient.show();
//        return a.exec();
//    }
//    else return 0;
// SavePasswordsToIni();
    return  a.exec();

}

